<?php
/**
 * Houses View for Congregation Component
 * 
 * @package    Joomla.Tutorials
 * @subpackage Components
 * @link http://docs.joomla.org/Developing_a_Model-View-Controller_Component_-_Part_4
 * @license		GNU/GPL
 */

// No direct access
defined( '_JEXEC' ) or die( 'Restricted access' );

jimport( 'joomla.application.component.view' );

/**
 * Houses View
 *
 * @package    Joomla.Tutorials
 * @subpackage Components
 */
class CongregationViewHouses extends CongregationView
{
	/**
	 * Sharings view display method
	 * @return void
	 **/
	function display($tpl = null)
	{
	
		$this->_p_id = JRequest::getCmd('p_id');
		JToolBarHelper::deleteList();
		JToolBarHelper::editListX();
		JToolBarHelper::addNewX();
		JToolBarHelper::back(JText::_('Back'), JRoute::_( 'index.php?option=com_congregation&controller=province'));
		// Get data from the model
		JHTML::_('behavior.tooltip');

		$default_limit  = $this->_mainframe->getCfg('list_limit');
		$limit          = $this->_mainframe->getUserStateFromRequest('joom.categories.limit', 'limit', $default_limit, 'int');
		$limitstart     = $this->_mainframe->getUserStateFromRequest('joom.categories.limitstart', 'limitstart', 0, 'int');
		$searchtext     = $this->_mainframe->getUserStateFromRequest('joom.categories.search', 'search', '');
		$sort           = $this->_mainframe->getUserStateFromRequest('joom.categories.sort', 'sort', 0);
		$filter         = $this->_mainframe->getUserStateFromRequest('joom.categories.filter', 'filter', 0);

		JRequest::setVar('limit',       (int) $limit);
		JRequest::setVar('limitstart',  (int) $limitstart);
		JRequest::setVar('search',      $searchtext);
		JRequest::setVar('sort',        (int) $sort);
		JRequest::setVar('filter',      $filter);


    $lists = array();

    // TODO: maybe rename first option to 'Treeview'
    $o_options[] = JHTML::_('select.option', 0, JText::_('JGA_COMMON_OPTION_ORDERBY_ORDERING_ASC'));
    #$o_options[] = JHTML::_('select.option', 1, JText::_('JGA_COMMON_OPTION_ORDERBY_ORDERING_DESC'));
    $o_options[] = JHTML::_('select.option', 2, JText::_('JGA_CATMAN_ORDERBY_CATPATH_ASC'));
    $o_options[] = JHTML::_('select.option', 3, JText::_('JGA_CATMAN_ORDERBY_CATPATH_DESC'));
    $o_options[] = JHTML::_('select.option', 4, JText::_('JGA_CATMAN_ORDERBY_DBID_ASC'));
    $o_options[] = JHTML::_('select.option', 5, JText::_('JGA_CATMAN_ORDERBY_DBID_DESC'));
    $o_options[] = JHTML::_('select.option', 6, JText::_('JGA_CATMAN_ORDERBY_CATNAME_ASC'));
    $o_options[] = JHTML::_('select.option', 7, JText::_('JGA_CATMAN_ORDERBY_CATNAME_DESC'));
    $o_options[] = JHTML::_('select.option', 8, JText::_('JGA_CATMAN_ORDERBY_DBOWNERID_ASC'));
    $o_options[] = JHTML::_('select.option', 9, JText::_('JGA_CATMAN_ORDERBY_DBOWNERID_DESC'));

    $lists['sort'] = JHTML::_('select.genericlist', $o_options, 'sort',
      'class="inputbox" size="1" onchange="document.adminForm.submit();"',
      'value', 'text', $sort);
		
		$items		= & $this->get( 'Data');
		
		$total		= & $this->get( 'Total' );
		
		if($items)
		{
			JToolBarHelper::title(   sprintf(JText::_( 'Province of %s' ), $items['0']->p_name), 'generic.png' );
		}
		else
		{
			JToolBarHelper::title(   JText::_( 'House manager' ), 'generic.png' );
		}
		
		jimport('joomla.html.pagination');
		$pagination = new JPagination($total, $limitstart, $limit);
		$this->assignRef('items',		$items);
		$this->assignRef('pagination',  $pagination);
		$this->assignRef('lists',       $lists);
		parent::display($tpl);
	}
	

}
